package carouselMap

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/carouselmap"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/rpc"
	"github.com/zeromicro/go-zero/core/logc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateCarouselMapLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 修改
func NewUpdateCarouselMapLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCarouselMapLogic {
	return &UpdateCarouselMapLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateCarouselMapLogic) UpdateCarouselMap(req *types.UpdateCarouselMapReq) (resp *types.Empty, err error) {
	if req.Id == 0 {
		return nil, code.ParamsInvalid
	}

	u, err := l.svcCtx.SettingService.CarouselMap.UpdateCarouselMap(l.ctx, &carouselmap.UpdateCarouselMapReq{
		Id: req.Id,
		Data: &carouselmap.AddCarouselMapReq{
			MerchantId: 1,                               // 商户ID
			Pic:        req.Data.Pic,                    // 图片地址
			JumpUrl:    req.Data.JumpUrl,                // 跳转链接
			Sort:       req.Data.Sort,                   // 排序
			Status:     rpc.StatusType(req.Data.Status), // 状态,0:关闭,1:显示
		},
	})

	if err != nil {
		logc.Error(l.ctx, "UpdateCarouselMap err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}
	resp = &types.Empty{}
	return
}
